﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ManageSystem
{
    public partial class ChangePwd : Form
    {
        private string userId;
        public ChangePwd()
        {
            InitializeComponent();
        }

        public ChangePwd(string userId)
        {
            InitializeComponent();
            this.userId = userId;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要修改密码?", "修改密码询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {


                string commend = "select * from UserInfo where UserId=" + userId + " and UserPwd='" + this.textBox1.Text + "'";
                SqlDataReader sqlDr = Utils.getDataReader(commend);
                if (!sqlDr.Read())
                {
                    MessageBox.Show("原密码输入错误!");
                    return;
                }

                if (!textBox2.Text.Equals(textBox3.Text))
                {
                    MessageBox.Show("两次密码输入不一致!");
                    return;
                }

                commend = "update UserInfo set UserPwd='" + textBox3.Text + "' where UserId=" + userId;
                if (Utils.ExecuteNoQuery(commend) != -1)
                {
                    MessageBox.Show("修改成功");
                    this.Close();

                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
